package com.xing.crm.service.impl;

import com.xing.crm.mapper.CourseOrderMapper;
import com.xing.crm.model.CourseOrder;
import com.xing.crm.model.MonthIncome;
import com.xing.crm.model.PageResult;
import com.xing.crm.service.CourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class CourseOrderServiceImpl implements CourseOrderService {


    @Autowired
    private CourseOrderMapper orderMapper;

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {
        PageResult<CourseOrder> result = new PageResult<CourseOrder>();

        result.setCode(0);
        result.setMsg("");
        HashMap<String, Object> params = new HashMap<String,Object>();
        params.put("condition",condition);
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);
        //获取总记录数据
        int totalCount = orderMapper.findCountByMap(params);
        result.setCount(totalCount);
        //获取查询的数据
        List<CourseOrder> list = orderMapper.findListByMap(params);

        result.setData(list);
        return result;
    }

    @Override
    public void save(CourseOrder order) {
        orderMapper.insert(order);
    }

    @Override
    public CourseOrder findByOrderId(String id) {

        return orderMapper.findByOrderId(id);
    }

    @Override
    public void deleteByOrderId(String id) {
        orderMapper.deleteByOrderId(id);
    }

    @Override
    public void update(CourseOrder order) {
        orderMapper.update(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return orderMapper.getMonthIncomes();
    }

    @Override
    public boolean isLogin(String name, String wecharno) {
        CourseOrder courseOrder=new CourseOrder();
        courseOrder.setName(name);
        courseOrder.setWecharno(wecharno);

        List<CourseOrder> users =orderMapper.selectUser(courseOrder);
        if(users.size()>0 ){
            return true;
        }
        return false;
    }



}
